

Imports DotNetNuke
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Common.Globals

Namespace SGW.ComunicadorWeb

    Public MustInherit Class EditMensaje
        Inherits Entities.Modules.PortalModuleBase

#Region "Private Members"

        Private MenID As Integer = Common.Utilities.Null.NullInteger

#End Region

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try

                'cmdHil_FechaCreacion.NavigateUrl = Common.Utilities.Calendar.InvokePopupCal(txtHil_FechaCreacion)
                'cmdHil_FechaCierre.NavigateUrl = Common.Utilities.Calendar.InvokePopupCal(txtHil_FechaCierre)

                ' Determine ItemId of ComunicadorWeb to Update
                If Not (Request.QueryString("MenID") Is Nothing) Then
                    MenID = Int32.Parse(Request.QueryString("MenID"))
                End If

                ' If this is the first visit to the page, bind the role data to the datalist
                If Page.IsPostBack = False Then

                    Me.DropDownUsuario.DataSource = UserController.GetUsers(PortalId)
                    Me.DropDownUsuario.DataBind()

                    cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" & Localization.GetString("DeleteItem") & "');")


                    If Not Common.Utilities.Null.IsNull(MenID) Then
                        ' get content
                        Dim objMsjs As New SGW_MensajesController
                        Dim objMensaje As SGW_MensajesInfo = objMsjs.GetSGW_Mensajes(MenID)

                        If Not objMensaje Is Nothing Then
                            Me.txtMen_FechaMensaje.Text = Trim(objMensaje.Men_FechaMensaje)
                            Me.Texteditor1.Text = objMensaje.Men_Mensaje
                            Me.DropDownUsuario.SelectedValue = objMensaje.Men_UsuarioID
                        Else ' security violation attempt to access item not related to this Module
                            Response.Redirect(NavigateURL(), True)
                        End If
                    End If
                End If

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' cmdCancel_Click runs when the cancel button is clicked
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdCancel.Click
            Try
                'Response.Redirect(NavigateURL(), True)
                'Response.Redirect(NavigateURL(Me.TabId, "", "sgwcomunicador=prioridades")
                Dim objmsjs As New SGW_MensajesController
                Dim objmsj As SGW_MensajesInfo = objmsjs.GetSGW_Mensajes(MenID)
                Response.Redirect(EditUrl("HiloID", objmsj.Men_HiloID))
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' cmdUpdate_Click runs when the update button is clicked
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUpdate.Click
            Try
                Dim objmensajes As New SGW_MensajesController
                Dim objMensaje As SGW_MensajesInfo = objmensajes.GetSGW_Mensajes(MenID)

                objMensaje.Men_FechaMensaje = Me.txtMen_FechaMensaje.Text
                objMensaje.Men_Mensaje = Me.Texteditor1.Text
                objMensaje.Men_UsuarioID = Me.DropDownUsuario.SelectedValue

                objmensajes.UpdateSGW_Mensajes(objMensaje)

                Response.Redirect(EditUrl("HiloID", objMensaje.Men_HiloID))

            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' cmdDelete_Click runs when the delete button is clicked
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub cmdDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDelete.Click
            Dim objMensajes As New SGW_MensajesController
            Dim objMensaje As New SGW_MensajesInfo
            Try
                ' Only attempt to delete the item if it exists already
                If Not Common.Utilities.Null.IsNull(MenID) Then

                    objMensaje = objMensajes.GetSGW_Mensajes(MenID)
                    objMensajes.DeleteSGW_Mensajes(objMensaje)

                End If

                ' Redirect back to the portal home page
                Response.Redirect(EditUrl("HiloID", objMensaje.Men_HiloID))
            Catch exc As Exception    'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
#End Region

    End Class

End Namespace
